<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <script type="text/javascript">
      Ext.onReady(function(){

        var trainTaskSnText = new Ext.form.TextField({
          fieldLabel:'检修任务编号',
          allowBlank:false,
          anchor: '90%',
          blankText:'项目名称不能为空！',
          name:'sn'
        })

        var trackDS = new Ext.data.Store({
          proxy:new Ext.data.HttpProxy({url:'/track/getAllTracks'}),
          autoLoad:true,
          reader:new Ext.data.JsonReader({
            totalProperty: 'total',
            root:'track'
          }, [
            {name:'track_name'},
            {name:'device_id'},
            {name:'id'}
          ])
        });

        var deviceIDText = new Ext.form.TextField({
          id:'device_id',
          fieldLabel:'设备ID',
          allowBlank:false,
          anchor: '90%',
          blankText:'设备ID不能为空！'
        })

        var stopTrack = new Ext.form.ComboBox({  //配合上面的departmentDS，完成动态生成的下拉框
          store: trackDS,
          hiddenName:'stop_track',            //显示时：这里写后台传送过来的字段，一旦和valueField相等，就进行显示。不相等为空。
          displayField:'track_name',              //store里面的值，用于显示在表面上的值
          valueField:'track_name',                  //store里面的值，和display联动
          typeAhead: true,
          allowBlank: false,
          minChars:1,
          readOnly:false,
          anchor: '90%',                    //在容器中的时候，自动按照容器百分比进行调整，会覆盖宽度的属性
          mode: 'remote',
          fieldLabel:'股道选择',
          forceSelection: true,
          triggerAction: 'all',
          emptyText:'请选择股道.....',
          selectOnFocus:true,
          listeners:{
            select:function(combo, record, index){
              deviceIDText.setValue(record.get('device_id'))
            }
          }
        });

        var DeadLineDateTime = new Ext.ux.form.DateTimeField({
          fieldLabel: '计划检修开工时间',
          width: 200,
          name: 'begin_time',
          invalidText: "您输入的日期格式不对，正确格式为2010-01-18",
          allowBlank: false,
          blankText: "完工时间必须选择",
          emptyText: '请选择时间...'
        });

        var train_id_combo = new Ext.form.TextField({  //配合上面的departmentDS，完成动态生成的下拉框
          name:'train_sn',
          id:'train_sn',
          typeAhead: true,
          disable:true,
          readOnly:true,
          anchor: '90%',                    //在容器中的时候，自动按照容器百分比进行调整，会覆盖宽度的属性
          fieldLabel:'列车编号'
        });

        var trainIdHidden = new Ext.form.Hidden({
          name:'train_id',
          id:'train_id'
        })

        train_id_combo.setValue(trainSn);
        trainIdHidden.setValue(trainId);

        var templateDS = new Ext.data.Store({
          proxy:new Ext.data.HttpProxy({url:'/template/getTemplates'}),
          autoLoad:true,
          reader:new Ext.data.JsonReader({
            totalProperty: 'totalProperty',
            root: 'template'
          }, [
            {name:'name'},                            //用作后面的displayField:
            {name:'id'}                                //用作后面的valueField:
          ])
        });
        var template_id_combo = new Ext.form.ComboBox({  //配合上面的departmentDS，完成动态生成的下拉框
          store: templateDS,
          hiddenName:'template_id',                //显示时：这里写后台传送过来的字段，一旦和valueField相等，就进行显示。不相等为空。
          displayField:'name',              //store里面的值，用于显示在表面上的值
          valueField:'id',                  //store里面的值，和display联动
          typeAhead: true,
          allowBlank:false,
          disable:true,
          minChars:1,
          readOnly:false,
          anchor: '90%',                    //在容器中的时候，自动按照容器百分比进行调整，会覆盖宽度的属性
          mode: 'remote',
          fieldLabel:'模板选择',
          forceSelection: true,
          triggerAction: 'all',
          emptyText:'请选择模板.....',
          selectOnFocus:true
        });

        var descriptionHtmlEditor = new Ext.form.HtmlEditor({
          fieldLabel: '内容',
          name: 'description',
          width:755,
          height:325
        })

        var newTrainTaskForm=new Ext.form.FormPanel({
          width:780,
          url:'/traintask/create?sub_type='+encodeURI('探伤'),
          labelAlign: 'top',
          buttonAlign:'center',
          fileUpload: true,
          autoHeight:true,
          bodyStyle: 'padding:5px',
          labelWidth:100,
          waitMsgTarget: true,
          frame: true,
          items:[{
              layout:'column',
              items:[{
                  columnWidth:.33,
                  layout:'form',
                  items:[trainTaskSnText]
                },{
                  columnWidth:.33,
                  layout:'form',
                  items:[stopTrack]
                },{
                  columnWidth:.33,
                  layout:'form',
                  items:[deviceIDText]
                }
              ]
            },
            {
              layout:'column',
              items:[trainIdHidden,{
                  columnWidth:.33,
                  layout:'form',
                  items:[train_id_combo]
                },{
                  columnWidth:.33,
                  layout:'form',
                  items:[template_id_combo]
                },{
                  columnWidth:.33,
                  layout:'form',
                  items:[DeadLineDateTime]
                }
              ]
            },descriptionHtmlEditor
          ],
          buttons:[{
              text:'确认保存',
              handler: function(){
                // check form value
                if (newTrainTaskForm.form.isValid()) {
                  Ext.MessageBox.confirm('警告','确定对<font color="red">'+trainSn
                    + '</font>进行探伤？<br>探伤后公里数将会被清零',function (button){
                    if(button=='yes'){
                      newTrainTaskForm.form.submit({
                        method: 'post',
                        waitMsg: '正在创建探伤计划...',
                        success: function(result, response){
                          if (response.result.info == "success") {
                            Ext.Ajax.request({                                      //探伤清零
                              url:'/daily/ts',
                              method:'post',
                              success:function(response,opts){
                              },
                              params: {"trainId":trainId}
                            });
                            newTrainTaskWin.destroy();                              //添加成功后，隐藏窗口，并刷新Grid
                          }
                          else {
                            Ext.MessageBox.alert('消息', response.result.info);
                          }
                        },
                        failure: function(result, response){
                          Ext.MessageBox.alert('提示', result.responseText);
                        }
                      });
                    }
                  })
                }
                else {
                  Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                }
              }
            },{
              text:'取消',
              handler:function(){
                newTrainTaskWin.destroy();
              }
            }]
        });

        newTrainTaskForm.render('new_train_task_form');
      });
    </script>
  </head>
  <body>
    <div id="new_train_task_form"></div>
  </body>
</html>
